
//#include "head.h"
//#include <stdio.h>
#include <signal.h>
#include <time.h>

#include <iostream>

#include <workflow/WFFacilities.h>
using std::cout;
using std::endl;

//
//初始化计数器的值为1
static WFFacilities::WaitGroup waitGroup(1);

void sighandler(int num)
{
    printf(">> sig num %d is comming\n", num);
    //调用一次done方法，计数器的值减1
    waitGroup.done();
}

void timerCallback(WFTimerTask * timertask)
{
    srand(clock());
    int number = rand() % 100;
    printf("timer task -> number: %d\n", number);

    auto nextTask = WFTaskFactory::create_timer_task(1000 * 1000, timerCallback);
    series_of(timertask)->push_back(nextTask);
}

void test0()
{
    signal(SIGINT, sighandler);
    
    auto timerTask = WFTaskFactory::create_timer_task(1000 * 1000, timerCallback);
    timerTask->start();

    //当调用wait方法会阻塞当前线程
    waitGroup.wait();

    cout << "test0 exit" << endl;
}


int main()
{
    test0();
    return 0;
}

